package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;

import org.fife.ui.rsyntaxtextarea.SyntaxConstants;

import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;

/**
 * 更新语法渲染器。
 * 
 * @author Ice Spring
 *
 */
public class UpdateSyntaxRendererAction extends AbstractAction{

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public UpdateSyntaxRendererAction(){

		super.putValue(Action.NAME, "Change content render style");
		super.putValue(Action.SHORT_DESCRIPTION, "Change the content type of this eidtor.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		TextEditor editor = ViewContext.getMainFrame().getCurrentTextEditor();

		if(editor != null){

			Object key = JOptionPane.showInputDialog(editor, 
					"选择一个内容类型来进行渲染", 
					"更改内容渲染模式", 
					JOptionPane.INFORMATION_MESSAGE, 
					null, 
					this.createUsableRender(), 
					editor.getSyntaxRenderStyle());

			if(key != null){

				editor.setSyntaxRendererStyle(key.toString());
			}
		}
	}

	private String[] createUsableRender(){

		return new String[]{
				SyntaxConstants.SYNTAX_STYLE_NONE,
				SyntaxConstants.SYNTAX_STYLE_JAVA,
				SyntaxConstants.SYNTAX_STYLE_SQL,
				SyntaxConstants.SYNTAX_STYLE_HTML,
				SyntaxConstants.SYNTAX_STYLE_XML,
		};
	}
}
